package ${packageName}.app.configuration;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.jpxx.base.http.converter.ResponseDataDecryptCallBack;
import com.jpxx.base.util.JsonElementHelper;
import com.jpxx.lib.klog.KLog;

/**
 *
 * 响应解密
 */
public class ResponseDataDecryptCallBackImpl implements ResponseDataDecryptCallBack {
    @Override
    public String doDataDecrypt(String rawResponse) {
        JsonObject encryptData = JsonElementHelper.jsonObjectValue(new JsonParser().parse(rawResponse));
        if(encryptData == null){
            return null;
        }

        Boolean encryptValue = JsonElementHelper.booleanValue(encryptData.get("encrypt"));
        if(encryptValue != null && encryptValue){
            //解密
            try {
                String encryptDataResponse = JsonElementHelper.stringValue(encryptData.get("data"));
                // 解密
                // String decryptResponseBodyStr = AndroidDes3Util.decode(encryptDataResponse);
                //JsonElement decryptResponseBodyJsonElement = new JsonParser().parse(decryptResponseBodyStr);
                //encryptData.add("data", decryptResponseBodyJsonElement);
                //return encryptData.toString();

                return null;
            } catch (Exception e) {
                KLog.e(e);
                //解密失败
                return null;
            }
        } else{
            //不需要解密
            return rawResponse;
        }
    }
}
